﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Collections;


public partial class CMS_Control_ViewControl : System.Web.UI.UserControl
{

    #region 外部属性
    private ShowMode _IsCheck = ShowMode.IsCheck;
    private ShowMode _IsVersion = ShowMode.IsVersion;
    private ShowMode _IsCanView = ShowMode.IsCanView;
    private ShowMode _IsEdit = ShowMode.IsEdit;
    private ShowMode _IsView = ShowMode.IsView;
    private ShowMode _IsNotPublic = ShowMode.IsNotPublic;
    private ShowMode _IsDel = ShowMode.IsDel;
    private bool _NowIsCheck;

    public enum ShowMode : int
    {
        IsCheck,
        IsVersion,
        IsCanView,
        IsEdit,
        IsView,
        IsNotPublic,
        IsDel

    }

    public ShowMode IsDel
    {
        get
        {
            return _IsDel;
        }
        set
        {
            _IsDel = value;
        }
    }

    public ShowMode IsNotPublic
    {
        get
        {
            return _IsNotPublic;
        }
        set
        {
            _IsNotPublic = value;
        }
    }

    public ShowMode IsCheck
    {
        get
        {
            return _IsCheck;
        }
        set
        {
            _IsCheck = value;
        }
    }


    public ShowMode IsVersion
    {
        get
        {
            return _IsVersion;
        }
        set
        {
            _IsVersion = value;
        }
    }

    public ShowMode IsEdit
    {
        get
        {
            return _IsEdit;
        }
        set
        {
            _IsEdit = value;
        }
    }

    public ShowMode IsCanView
    {
        get
        {
            return _IsCanView;
        }
        set
        {
            _IsCanView = value;
        }
    }

    public ShowMode IsView
    {
        get
        {
            return _IsView;
        }
        set
        {
            _IsView = value;
        }
    }

    public bool NowIsCheck
    {
        get
        {
            return _NowIsCheck;
        }
        set
        {
            _NowIsCheck = value;
        }
    }
    #endregion

    Usas.Common.Cms.CurrentInfo cinfo = new Usas.Common.Cms.CurrentInfo();


    protected void Page_Load(object sender, EventArgs e)
    {


    }

    public void AddMode(Usas.Common.Cms.Role.RedType rt,string id)
    {
        PartControl1.Visible = false;

        quxiaoxianshi.Checked = !true;
        quxiaoxianshi.Enabled = false;
        ArtType1.Value = "2";

        SetRole1.SetValue(Convert.ToInt32(id), rt);

        SetRoleEdit1.SetValue(Convert.ToInt32(id), rt);
    }


    /// <summary>
    /// 赋值
    /// </summary>
    /// <param name="id">article编号</param>
    /// <param name="e">编辑权限</param>
    /// <param name="v">查看权限</param>
    /// <param name="c">是否需要审核</param>
    /// <param name="ckk">是否已审核（f 是）</param>
    /// <returns>文章状态</returns>
    public ShowMode SetValue(int id,bool check)
    {
        //ckk = ckk == "t" ? "1" : "0";
        Usas.BLL.Cms.cmsArticle ar = new Usas.BLL.Cms.cmsArticle();
        Usas.Model.Cms.cmsArticle arm = new Usas.Model.Cms.cmsArticle();
        Usas.BLL.Cms.cms_purview_setting cps = new Usas.BLL.Cms.cms_purview_setting();
        Usas.Common.Cms.Role ro = new Usas.Common.Cms.Role();
        Usas.BLL.Cms.UsasDB udb = new Usas.BLL.Cms.UsasDB();

        arm.ArtId = id;

        arm = ar.GetModel(arm.ArtId);

        DataSet ds = cps.GetList("p_table='a' and p_pid=" + id.ToString());
        bool edit = false;
        bool view = false;
        bool writer = arm.Writer == Convert.ToInt32(cinfo.GetEmpId()) ? true : false;

        if (ds != null && ds.Tables[0] != null)
        {
            string ros = ro.GetSelfSettingRole();
            edit = ds.Tables[0].Select(ros + " and p_type='1'", "p_id").Length > 0 ? true : false;
            view = ds.Tables[0].Select(ros + " and p_type='0'", "p_id").Length > 0 ? true : false;
        }
        if (!view && !edit)
        {
            Cont.Visible = false;
            PartControl1.Visible = false;
            return ShowMode.IsView;
        }
        else
        {
            if (arm.ArtFormat != 1)
            {

                PartControl1.Visible = false;

                topic.Text = arm.ArtTopic;
                key.Text = arm.ArtKeys;
                zhaoyao.Text = arm.ArtSummary;
                DataSet zuozheds = udb.SelEmployees("EmployeeId=" + arm.Writer);
                zuozhe.Text = zuozheds != null && zuozheds.Tables[0].Rows.Count > 0 ? zuozheds.Tables[0].Rows[0]["EmpName"].ToString() : "";
                

                quxiaoxianshi.Checked = !!arm.CanView;

                if (!!quxiaoxianshi.Checked)
                {
                    Del.Visible = true;
                }

                CanView.Value = (!quxiaoxianshi.Checked).ToString();

                dianji.Text = arm.hits.ToString();
                //HtmlEditor1.ShowFck(ArtType1.IsHtml());
                HtmlEditor1.SetValue(arm.ArtFileName, arm.ArtDirectory, arm.ArtTopic);

                SetRole1.SetValue(Convert.ToInt32(arm.ArtId), Usas.Common.Cms.Role.RedType.Article);
                SetRoleEdit1.SetValue(Convert.ToInt32(arm.ArtId), Usas.Common.Cms.Role.RedType.Article);

                Version1.GetValue(arm.ArtId.ToString(), true);

                oldorder.Value = arm.ArtOrder.ToString();
                hid.Value = id.ToString();
                dir.Value = arm.ArtDirectory;
                filename.Value = arm.ArtFileName;
                hidtype.Value = arm.TypeId.ToString();
                hidborder.Value = arm.BorderId.ToString();

                order.Value = arm.ArtOrder.ToString();
                CbAudit.Checked = arm.Audit;
                hidartp.Value = arm.ParentArtId.ToString();
                oldTime.Value = arm.ModfiyTime.ToString();

                ArtType1.Value = arm.ArtFormat.ToString();
                oldformat.Value = ArtType1.Value;

                int pid = arm.ParentArtId == 0 ? Convert.ToInt32(arm.BorderId) : Convert.ToInt32(arm.ParentArtId);
                Usas.Common.Cms.Role.RedType ptable = arm.ParentArtId == 0 ? Usas.Common.Cms.Role.RedType.Border : Usas.Common.Cms.Role.RedType.Article;
                string[] isf = ro.GetFatherDir(ptable, pid, true);

                if (isf != null)
                {
                    SetTopChoose1.StartStr = isf[0] + "#" + isf[1] + "#" + ro.GetTable(ptable) + "#" + pid;
                    SetTopChoose1.IsChoose = true;

                    //SetTopChoose1.Name = isf[2];
                }
                else
                {
                    SetTopChoose1.IsChoose = false;
                }
                SetTopChoose1.SetId = arm.IsTop;
                switch (arm.PublishStatus)
                {
                    case 0:
                        IsCheckTxt.InnerText = "未发布";
                        //return ShowMode.IsNotPublic;
                        return check || edit || arm.Writer == Convert.ToInt32(cinfo.GetEmpId()) ? ShowMode.IsNotPublic : ShowMode.IsView;
                        break;
                    case 1:
                        IsCheckTxt.InnerText = "已发布";
                        return check || edit || arm.Writer == Convert.ToInt32(cinfo.GetEmpId()) ? ShowMode.IsEdit : ShowMode.IsView;
                        break;
                    case 2:
                        IsCheckTxt.InnerText = "审核中";
                        return check || edit || arm.Writer == Convert.ToInt32(cinfo.GetEmpId()) ? ShowMode.IsDel : ShowMode.IsView;
                        break;
                    case 3:
                        IsCheckTxt.InnerText = "已删除";
                        //return ShowMode.IsDel;
                        return check || edit || arm.Writer == Convert.ToInt32(cinfo.GetEmpId()) ? ShowMode.IsDel : ShowMode.IsView;
                        break;
                }
                return ShowMode.IsView;

            }
            else
            {
               BindPart(id);
               return ShowMode.IsView;
            }
        }



        //bool ck = c == "0" ? true : false;
        //NowIsCheck = !ck;



        //if (isf == "f")
        //{

        //}
        //else
        //{
        //    if (arm.ParentArtId == 0)
        //    {
        //        SetTopChoose1.StartStr = isf + "#" + fid + "#" + "b" + "#" + arm.BorderId.ToString();

        //    }
        //    else
        //    {
        //        SetTopChoose1.StartStr = isf + "#" + fid + "#" + "a" + "#" + arm.ParentArtId.ToString();
        //    }
        //}


        //switch (arm.PublishStatus)
        //{
        //    case 0:
        //        IsCheckTxt.InnerText = "未发布";
        //        return e == "t" ? ShowMode.IsNotPublic : ShowMode.IsView;
        //        break;
        //    case 1:
        //        IsCheckTxt.InnerText = "已发布";
        //        return e == "t" ? ShowMode.IsEdit : ShowMode.IsView;
        //        break;
        //    case 2:
        //        IsCheckTxt.InnerText = "审核中";
        //        return e == "t" ? ShowMode.IsDel : ShowMode.IsView;
        //        break;
        //    case 3:
        //        IsCheckTxt.InnerText = "已删除";
        //        return e == "t" ? ShowMode.IsDel : ShowMode.IsView;
        //        break;
        //    default:
        //        return ShowMode.IsView;
        //}
        //}
        //else
        //{
        //BindPart(id, v, e, c, ckk);
        ;
        //}
    }



    private void BindPart(int id)
    {
        
        Cont.Visible = false;
        PartControl1.IntiPart(Usas.Common.Cms.Role.RedType.Article, id);
        
    }

    public Usas.Model.Cms.cmsArticle GetValue()
    {
        return null;
    }

    /// <summary>
    /// 保存
    /// </summary>
    /// <param name="c">是否需要审核</param>
    public void Save()
    {
        try
        {
            Usas.BLL.Cms.cmsArticle ar = new Usas.BLL.Cms.cmsArticle();
            Usas.Model.Cms.cmsArticle arm = new Usas.Model.Cms.cmsArticle();
            Usas.Common.Cms.CurrentInfo cinfo = new Usas.Common.Cms.CurrentInfo();
            Usas.Common.Cms.FileControl fc = new Usas.Common.Cms.FileControl();

            //bool ck = c == "0" ? true : false;


            arm.ArtId = Convert.ToInt32(hid.Value);
            arm.ArtTopic = topic.Text;
            arm.ArtKeys = key.Text;
            arm.ArtSummary = zhaoyao.Text;
            arm.ModfiyTime = DateTime.Now;
            arm.Modify = Convert.ToInt32(cinfo.GetEmpId());
            //arm.Writer = zuozhe.Text;
            arm.ParentArtId = Convert.ToInt32(hidartp.Value);

            //arm.Audit = !ck;
            arm.ArtFormat = Convert.ToInt32(ArtType1.Value);
            arm.Audit = CbAudit.Checked;
            arm.TypeId = Convert.ToInt32(hidtype.Value);
            arm.BorderId = Convert.ToInt32(hidborder.Value);
            arm.ArtFormat = Convert.ToInt32(ArtType1.Value);
            arm.CanView = !!quxiaoxianshi.Checked;

            arm.ArtOrder = long.Parse(oldorder.Value);
            if (!ArtType1.IsHtml() && oldformat.Value == ArtType1.Value && HtmlEditor1.GetFileUpload.FileName == "")
            {
                arm.ArtFileName = null;
                arm.ArtDirectory = null;

                arm.ModfiyTime = Convert.ToDateTime(oldTime.Value);
            }
            else
            {
                ArrayList arr = fc.UpdateFile(ArtType1.IsHtml(), dir.Value, filename.Value, HtmlEditor1.GetValue(), HtmlEditor1.GetFileUpload, DateTime.Now.ToFileTime().ToString());
                if (arr != null)
                {
                    arm.ArtDirectory = arr[0].ToString();
                    arm.ArtFileName = arr[1].ToString();
                }
                else
                {
                    arm.ArtFileName = null;
                    arm.ArtDirectory = null;

                    arm.ModfiyTime = Convert.ToDateTime(oldTime.Value);
                }
            }

            arm.IsTop = SetTopChoose1.SetId == "-1" ? "" : SetTopChoose1.SetId;

            if (arm.CanView)
            {
                arm.PublishStatus = 3;
            }
            else
            {
                arm.PublishStatus = 0;
            }

            ar.Update(arm);

            SetRole1.SetValueTran(SetRoleEdit1.GetList(), SetRole1.GetList(), Convert.ToInt32(arm.ArtId), Usas.Common.Cms.Role.RedType.Article);
            SetRoleEdit1.SetValueTran(SetRoleEdit1.GetList(), Convert.ToInt32(arm.ArtId), Usas.Common.Cms.Role.RedType.Article);

            if (arm.PublishStatus == 3)
            {
                SendEmail(Convert.ToInt32(arm.BorderId), arm.ArtTopic, Convert.ToInt32(arm.ArtId), true);
            }
        }
        catch(Exception ex)
        {
            throw new Exception(ex.Message);
        }

        //if (!ck)
        //{
        //    SendEmail(Convert.ToInt32(arm.BorderId), arm.ArtTopic, Convert.ToInt32(arm.ArtId), TempCanView);
        //}
    }

    //发送邮件
    private void SendEmail(int bid, string Topic, int aid, bool IsDel)
    {
        Usas.BLL.Cms.cmsBorder bo = new Usas.BLL.Cms.cmsBorder();
        Usas.Model.Cms.cmsBorder bom = new Usas.Model.Cms.cmsBorder();
        Usas.BLL.Cms.UsasDB udb = new Usas.BLL.Cms.UsasDB();
        Usas.Common.Cms.Role ro = new Usas.Common.Cms.Role();

        bom = bo.GetModel(bid);
        DataSet ds = udb.SelEmployees("Employees.EmployeeId=" + bom.CheckPerson.ToString());
        if (ds != null)
        {
            if (ds.Tables[0].Rows.Count > 0)
            {
                if (ds.Tables[0].Rows[0]["EMAIL"] != null)
                {



                    string EMAIL = ds.Tables[0].Rows[0]["EMAIL"].ToString();
                    ArrayList Earr = new ArrayList();
                    Earr.Add(EMAIL);

                    //获取目录
                    string AppPath = "";
                    HttpContext HttpCurrent = HttpContext.Current;
                    HttpRequest Req;
                    if (HttpCurrent != null)
                    {
                        Req = HttpCurrent.Request;

                        string UrlAuthority = Req.Url.GetLeftPart(UriPartial.Authority);
                        if (Req.ApplicationPath == null || Req.ApplicationPath == "/")
                            //直接安装在   Web   站点 
                            AppPath = UrlAuthority;
                        else
                            //安装在虚拟子目录下 
                            AppPath = UrlAuthority + Req.ApplicationPath;
                    }

                    string NewUrl = AppPath + "/CMS/Admin/Check.aspx?id=" + aid + "&check=" + ro.GetMd5Str32(aid + "check") + "&eid=" + cinfo.GetEmpId() + "&ename=" + Server.UrlEncode(cinfo.GetEmpName());

                    string DelStr = "";
                    if (IsDel)
                    {
                        //DelStr = " <span style='color:red'>删除了一则内容，以下为链接地址，请查阅（点击“通过审核”放入回收站，以便日后复原）<br/><a href='" + NewUrl + "' >" + NewUrl + "</a></span>";

                        DelStr = " <span style='color:red'>删除了一则内容</span> ：" + Topic;
                    }
                    else
                    {
                        DelStr = " 发布了一则内容，请审核，以下为链接地址<br/><a href='" + NewUrl + "' >" + NewUrl + "</a>";
                    }

                    ro.SendMail(Earr, System.Configuration.ConfigurationSettings.AppSettings["SendEmailFrom"].ToString(),
                        System.Configuration.ConfigurationSettings.AppSettings["SendEmailPassword"].ToString(), "内容管理审核[" + Topic + "]",
                        "您好，<br>" + cinfo.GetEmpName() + DelStr,
                        Convert.ToInt32(System.Configuration.ConfigurationSettings.AppSettings["SendEmailPort"]), System.Configuration.ConfigurationSettings.AppSettings["SendEmailHost"].ToString(), false);

                }
            }
        }
    }


    /// <summary>
    /// 添加版本
    /// </summary>
    /// <param name="c">是否需要审核</param>
    /// <returns>添加后ID</returns>
    public int AddVersion()
    {
        try
        {
            Usas.BLL.Cms.cmsArticle ar = new Usas.BLL.Cms.cmsArticle();
            Usas.Model.Cms.cmsArticle arm = new Usas.Model.Cms.cmsArticle();
            Usas.Common.Cms.CurrentInfo cinfo = new Usas.Common.Cms.CurrentInfo();
            Usas.Common.Cms.FileControl fc = new Usas.Common.Cms.FileControl();

            //arm.ArtId = Convert.ToInt32(hid.Value);
            arm = ar.GetModel(Convert.ToInt32(hid.Value));

            arm.ArtTopic = topic.Text;
            arm.ArtKeys = key.Text;
            arm.ArtSummary = zhaoyao.Text;
            arm.ModfiyTime = DateTime.Now;
            arm.Modify = Convert.ToInt32(cinfo.GetEmpId());
            arm.Writer = Convert.ToInt32(cinfo.GetEmpId());


            //arm.Audit = 0;
            arm.Audit = CbAudit.Checked;
            arm.ArtFormat = Convert.ToInt32(ArtType1.Value);
            arm.TypeId = Convert.ToInt32(hidtype.Value);
            arm.BorderId = Convert.ToInt32(hidborder.Value);
            arm.ArtFormat = Convert.ToInt32(ArtType1.Value);
            arm.CanView = !!quxiaoxianshi.Checked;
            arm.ParentArtId = Convert.ToInt32(hidartp.Value);
            arm.EditTime = DateTime.Now;
            if (arm.CanView)
            {
                arm.PublishStatus = 3;
            }
            else
            {
                arm.PublishStatus = 0;
            }

            if (!ArtType1.IsHtml() && oldformat.Value == ArtType1.Value && HtmlEditor1.GetFileUpload.FileName == "")
            {
            }
            else
            {
                ArrayList arr = fc.UpdateFile(ArtType1.IsHtml(), null, null, HtmlEditor1.GetValue(), HtmlEditor1.GetFileUpload, DateTime.Now.ToFileTime().ToString());
                if (arr != null)
                {
                    arm.ArtDirectory = arr[0].ToString();
                    arm.ArtFileName = arr[1].ToString();
                }
                else
                {
                    arm.ArtFileName = null;
                    arm.ArtDirectory = null;
                }
            }

            int backaid = ar.AddVersion(arm, Convert.ToInt32(hid.Value));
            if (backaid > 0)
            {
                SetRole1.SetValueTran(SetRoleEdit1.GetList(), SetRole1.GetList(), backaid, Usas.Common.Cms.Role.RedType.Article);
                SetRoleEdit1.SetValueTran(SetRoleEdit1.GetList(), backaid, Usas.Common.Cms.Role.RedType.Article);
            }
            else
            {
                backaid = -1;
            }
            //try
            //{
            //    if (backaid > 0)
            //    {
            //        SendEmail(Convert.ToInt32(arm.BorderId), arm.ArtTopic, Convert.ToInt32(backaid), false);
            //    }
            //}
            //catch
            //{
            //}

            return backaid;

        }
        catch
        {
            return -1;
        }
    }
    /// <summary>
    /// 审核
    /// </summary>
    /// <returns>编号</returns>
    public int PassCheck()
    {
        //Usas.BLL.Cms.cmsArticle ar = new Usas.BLL.Cms.cmsArticle();
        //Usas.Model.Cms.cmsArticle arm = new Usas.Model.Cms.cmsArticle();
        //Usas.Common.Cms.CurrentInfo cinfo = new Usas.Common.Cms.CurrentInfo();
        //Usas.Common.Cms.FileControl fc = new Usas.Common.Cms.FileControl();

        //arm.ArtId = Convert.ToInt32(hid.Value);
        //arm.ArtTopic = topic.Text;
        //arm.ArtKeys = key.Text;
        //arm.ArtSummary = zhaoyao.Text;
        //arm.ModfiyTime = DateTime.Now;
        //arm.Modify = cinfo.GetEmpName();
        //arm.Writer = zuozhe.Text;
        //arm.ParentArtId = Convert.ToInt32(hidartp.Value);
        //arm.Audit = false;

        //arm.ArtFormat = Convert.ToInt32(ArtType1.Value);

        //arm.TypeId = Convert.ToInt32(hidtype.Value);
        //arm.BorderId = Convert.ToInt32(hidborder.Value);
        //arm.ArtFormat = Convert.ToInt32(ArtType1.Value);
        //arm.CanView = !!quxiaoxianshi.Checked;

        //if (!ArtType1.IsHtml() && oldformat.Value == ArtType1.Value && HtmlEditor1.GetFileUpload.FileName == "")
        //{
        //    arm.ArtFileName = null;
        //    arm.ArtDirectory = null;
        //}
        //else
        //{
        //    ArrayList arr = fc.UpdateFile(ArtType1.IsHtml(), dir.Value, filename.Value, HtmlEditor1.GetValue(), HtmlEditor1.GetFileUpload, DateTime.Now.ToFileTime().ToString());
        //    if (ar != null)
        //    {
        //        arm.ArtDirectory = arr[0].ToString();
        //        arm.ArtFileName = arr[1].ToString();
        //    }
        //    else
        //    {
        //        arm.ArtFileName = null;
        //        arm.ArtDirectory = null;
        //    }
        //}

        //ar.Update(arm);
        //return Convert.ToInt32(arm.ArtId);
        return 0;
    }

    /// <summary>
    /// 添加
    /// </summary>
    /// <param name="c">是否需要审核</param>
    /// <param name="type">TypeId</param>
    /// <param name="border">BorderId</param>
    /// <param name="pid">article parentid</param>
    /// <returns>是否成功</returns>
    public int Add(int type, int border, int pid)
    {

        try
        {
            Usas.BLL.Cms.cmsArticle ar = new Usas.BLL.Cms.cmsArticle();
            Usas.Model.Cms.cmsArticle arm = new Usas.Model.Cms.cmsArticle();
            Usas.Common.Cms.CurrentInfo cinfo = new Usas.Common.Cms.CurrentInfo();
            Usas.Common.Cms.FileControl fc = new Usas.Common.Cms.FileControl();


            arm.ArtTopic = topic.Text;
            arm.ArtKeys = key.Text;
            arm.ArtSummary = zhaoyao.Text;
            arm.ModfiyTime = DateTime.Now;
            arm.Modify = Convert.ToInt32(cinfo.GetEmpId());
            arm.Writer = Convert.ToInt32(cinfo.GetEmpId());
            arm.ArtOrder = Convert.ToInt32(DateTime.Now.ToString("yyMMddHH"));
            //bool ck = c == "0" ? true : false;
            //arm.Audit = !ck;
            arm.ArtFormat = Convert.ToInt32(ArtType1.Value);
            arm.Audit = CbAudit.Checked;
            arm.TypeId = type;
            arm.BorderId = border;
            arm.ParentArtId = pid;

            arm.ArtFormat = Convert.ToInt32(ArtType1.Value);
            arm.CanView = !!quxiaoxianshi.Checked;
            arm.PublishStatus = 0;

            if (!ArtType1.IsHtml() && oldformat.Value == ArtType1.Value && HtmlEditor1.GetFileUpload.FileName == "")
            {
                arm.ArtFileName = null;
                arm.ArtDirectory = null;
            }
            else
            {
                ArrayList arr = fc.UpdateFile(ArtType1.IsHtml(), dir.Value, filename.Value, HtmlEditor1.GetValue(), HtmlEditor1.GetFileUpload, DateTime.Now.ToFileTime().ToString());
                if (ar != null)
                {
                    arm.ArtDirectory = arr[0].ToString();
                    arm.ArtFileName = arr[1].ToString();
                }
                else
                {
                    arm.ArtFileName = null;
                    arm.ArtDirectory = null;
                }
            }


            int backaid = ar.Add(arm);


            if (backaid > 0)
            {
                SetRole1.SetValueTran(SetRoleEdit1.GetList(), SetRole1.GetList(),backaid, Usas.Common.Cms.Role.RedType.Article);
                SetRoleEdit1.SetValueTran(SetRoleEdit1.GetList(), backaid, Usas.Common.Cms.Role.RedType.Article);
            }

            return backaid;
        }
        catch
        {
            return -1;
        }
    }


    public bool ArticlePublic(int id, bool needcheck, int? checkperson)
    {
        Usas.BLL.Cms.cmsArticle ar = new Usas.BLL.Cms.cmsArticle();
        Usas.Model.Cms.cmsArticle arm = new Usas.Model.Cms.cmsArticle();
        Usas.BLL.Cms.cmsBorder bo = new Usas.BLL.Cms.cmsBorder();
        Usas.Model.Cms.cmsBorder bom = new Usas.Model.Cms.cmsBorder();

        arm = ar.GetModel(id);


        
        if (needcheck)
        {
            arm.PublishStatus = 2;
            //arm.Audit = true;
        }
        else
        {
            arm.PublishStatus = 1;
            //arm.Audit = false;
        }

        ar.Update(arm);


        if (needcheck)
        {
            SendEmail(Convert.ToInt32(arm.BorderId), arm.ArtTopic, Convert.ToInt32(arm.ArtId), false);
        }

        return true;
    }
    protected void Del_Click(object sender, EventArgs e)
    {
        Usas.BLL.Cms.cmsArticle ar = new Usas.BLL.Cms.cmsArticle();
        Usas.Model.Cms.cmsArticle arm = new Usas.Model.Cms.cmsArticle();

        ar.Delete(Convert.ToInt32(hid.Value));
        this.Page.ClientScript.RegisterStartupScript(GetType(), "Msg", "alert('删除成功');", true);
        //Response.Redirect("~/CMS/Admin/Info.aspx?info=" + Server.UrlEncode("删除成功!"));


    }

    /// <summary>
    /// 增改 验证（必须）
    /// </summary>
    /// <returns></returns>
    public string Val()
    {
        if (topic.Text.Trim().Length <= 0)
        {
            return "内容标题不得为空";
        }

        if (SetRole1.Check().Trim().Length > 0)
        {
            return SetRole1.Check();
        }

        if (SetRoleEdit1.Check().Trim().Length > 0)
        {
            return SetRoleEdit1.Check();
        }


        return "";
    }

    /// <summary>
    /// 编辑初始化
    /// </summary>
    /// <param name="id">Id</param>
    /// <param name="f">是否需要审核</param>
    public void EditInit(int id, string f)
    {

        SetValue(id,false);
        HtmlEditor1.FckHeight = 220;
        HtmlEditor1.FckInit();
    }
    /// <summary>
    /// 添加初始化
    /// </summary>
    public void AddInit()
    {
        HtmlEditor1.FckHeight = 220;
        HtmlEditor1.FckInit();
        //AddMode();
    }
    /// <summary>
    ///  设置删除属性
    /// </summary>
    /// <param name="Vis"></param>
    public void DelVis(bool Vis)
    {
        PartControl1.SetDel(Vis);
        Del.Visible = Vis;
    }


}
